<script setup lang="ts">

import comA from "@/components/comA.vue";
import comB from "@/components/comB.vue";
import {shallowRef} from "vue";

let com = shallowRef(comA)

function changeCom() {
  com.value = com.value == comA ? comB : comA
}
</script>

<template>
  keepAlive
  <!--  组件缓存-->
  <keep-alive>
    <component :is="com"></component>
  </keep-alive>
  <button @click="changeCom">changeCom</button>
</template>

<style scoped>

</style>
